package ThreadDome;
public class Dome12 {
    public static void main(String[] args) throws InterruptedException {
        t1.start();
        t2.start();
        System.out.println("main线程等待t2执行完毕");
        t2.join();
        for (int i = 0; i < 3; i++) {
            Thread.sleep(1000);
            System.out.println("main线程运行中");
        }
    }
    static Thread t1 = new Thread(()-> {
        for (int i = 0; i < 3; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("t1线程运行中");
        }
    });
    static Thread t2 = new Thread(()-> {
        System.out.println("t2等待t1执行");
        for (int i = 0; i < 3; i++) {
            try {
                //先等待t1线程执行
                t1.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("t2线程运行中");
        }
    });
}